package sma.trabajoFinal.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import sma.trabajoFinal.util.UtilJPA;

@Entity
@Table(name = "Cliente")
@XmlRootElement
public class Cliente implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Basic(optional = false)
	@Column(name = "idCliente")
	private Integer idCliente;

	@Column(name = "nombre")
	private String nombre;

	/**
	 * 
	 */
	public void insertar() {
		try {

			ClienteJpaController clienteController = new ClienteJpaController(
					UtilJPA.getEntityManagerFactory());

			clienteController.create(this);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	public void modificar() {
		try {

			ClienteJpaController clienteController = new ClienteJpaController(
					UtilJPA.getEntityManagerFactory());

			clienteController.edit(this);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	public void borrar() {
		try {

			ClienteJpaController clienteController = new ClienteJpaController(
					UtilJPA.getEntityManagerFactory());

			clienteController.destroy(this);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	public List<Cliente> buscar() {

		List<Cliente> rList = null;

		try {

			ClienteJpaController clienteController = new ClienteJpaController(
					UtilJPA.getEntityManagerFactory());

			rList = clienteController.findClienteEntities();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return rList;
	}

	/**
	 * 
	 * @return
	 */
	public String getNombre() {
		return nombre;
	}

	/**
	 * 
	 * @param nombre
	 */
	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	/**
	 * 
	 * @return
	 */
	public Integer getIdCliente() {
		return idCliente;
	}

	/**
	 * 
	 * @param idCliente
	 */
	public void setIdCliente(Integer idCliente) {
		this.idCliente = idCliente;
	}

}
